<#ibizinclude>
../../../@MACRO/LANG_FUN.ftl
</#ibizinclude>
<#if item.getPSViewLogic?? && item.getPSViewLogic()??>
<#assign viewlogic = item.getPSViewLogic()/>
    /**
     * 打开编辑数据视图
     *
     * @param {any[]} args
     * @param {*} [params]
     * @param {*} [fullargs]
     * @param {*} [$event]
     * @param {*} [xData]
     * @memberof ${srfclassname('${view.name}')}
     */
    public ${item.name}(args: any[],fullargs?:any[],params?: any, $event?: any, xData?: any) {
    <#if viewlogic.getPSAppUILogicRefViews?? && viewlogic.getPSAppUILogicRefViews()??>
    <#list viewlogic.getPSAppUILogicRefViews() as appUILogicRefView>
    <#if appUILogicRefView_index == 0><#assign curOPenLogicRefView = appUILogicRefView /></#if>
    </#list>
    </#if>
    <#if viewlogic.getOpenDataPSAppView()??>
        const localContext: any = <#if curOPenLogicRefView?? && curOPenLogicRefView.getPSNavigateContexts?? && curOPenLogicRefView.getPSNavigateContexts()??><@getNavigateContext curOPenLogicRefView /><#else>null</#if>;
        const localViewParam: any =<#if curOPenLogicRefView?? && curOPenLogicRefView.getPSNavigateParams?? && curOPenLogicRefView.getPSNavigateParams()??><@getNavigateParams curOPenLogicRefView /><#else>null</#if>;
        <#assign dataview = viewlogic.getOpenDataPSAppView()/>
        const data: any = {};
        let tempContext = JSON.parse(JSON.stringify(this.context));
        if(args.length >0){
            Object.assign(tempContext,args[0]);
        }
        <#-- BEGIN：导航参数 -->
        <#if curOPenLogicRefView?? && curOPenLogicRefView.getPSNavigateContexts?? && curOPenLogicRefView.getPSNavigateContexts()??>
        if(localContext && Object.keys(localContext).length >0){
            let _context:any = this.$util.computedNavData(args[0],this.context,this.viewparams,localContext);
            Object.assign(tempContext,_context);
        }
        </#if>
        <#if curOPenLogicRefView?? && curOPenLogicRefView.getPSNavigateParams?? && curOPenLogicRefView.getPSNavigateParams()??>
        if(localViewParam && Object.keys(localViewParam).length >0){
            let _param:any = this.$util.computedNavData(args[0],this.context,this.viewparams,localViewParam);
            Object.assign(data,_param);
        }
        </#if>
        <#-- END：导航参数 -->
        <#--  BEGIN：准备参数  -->
        <#if dataview.isRedirectView() && dataview.getViewType() != "DEREDIRECTVIEW">
        const deResParameters: any[] = [];
        const parameters: any[] = [];
        <#else>
        <#--  BEGIN：是否应用实体视图  -->
        <#if dataview.isPSDEView()>
        <#-- 存在关系start -->
        <#if dataview.getPSAppDERSPathCount() gt 0>
        <#list 1..dataview.getPSAppDERSPathCount() as count>
        <#assign condition = ''/>
        <#list dataview.getPSAppDERSPath(count_index)  as deRSPath>
            <#if deRSPath.getMajorPSAppDataEntity?? && deRSPath.getMajorPSAppDataEntity()??>
                <#assign _dataEntity = deRSPath.getMajorPSAppDataEntity()/>
                <#assign condition>${condition}tempContext.${_dataEntity.getCodeName()?lower_case} && </#assign>
            </#if>
        </#list>
        </#list>
        let deResParameters: any[] = [];
        <#-- 如果是主实体需对context判断start -->
        <#if dataview.getPSAppDataEntity().isMajor()>
        if(${condition}true){
            deResParameters = [
            <#list dataview.getPSAppDERSPath(dataview.getPSAppDERSPathCount() - 1) as deRSPath>
            <#assign majorPSAppDataEntity = deRSPath.getMajorPSAppDataEntity()/>
            { pathName: '${srfpluralize(majorPSAppDataEntity.codeName)?lower_case}', parameterName: '${majorPSAppDataEntity.getCodeName()?lower_case}' },
            </#list>
            ]
        }
        <#else>
        deResParameters = [
            <#list dataview.getPSAppDERSPath(dataview.getPSAppDERSPathCount() - 1) as deRSPath>
            <#assign majorPSAppDataEntity = deRSPath.getMajorPSAppDataEntity()/>
            { pathName: '${srfpluralize(majorPSAppDataEntity.codeName)?lower_case}', parameterName: '${majorPSAppDataEntity.getCodeName()?lower_case}' },
            </#list>
        ];
        </#if>
        <#-- 如果是主实体需对context判断end -->
        <#else>
        const deResParameters: any[] = [];
        </#if>
        <#-- 存在关系end -->
        <#else>
        const deResParameters: any[] = [];
        </#if>
        <#--  END：是否应用实体视图  -->
        <#if dataview.getOpenMode() == 'INDEXVIEWTAB' || dataview.getOpenMode() == ''>
        <#--  BEGIN：是否应用实体视图  -->
        <#if dataview.isPSDEView()>
        <#assign appDataEntity = dataview.getPSAppDataEntity()/>
        const parameters: any[] = [
            { pathName: '${srfpluralize(appDataEntity.codeName)?lower_case}', parameterName: '${appDataEntity.getCodeName()?lower_case}' },
            { pathName: '${dataview.getPSDEViewCodeName()?lower_case}', parameterName: '${dataview.getPSDEViewCodeName()?lower_case}' },
        ];
        <#else>
        const parameters: any[] = [
            { pathName: '${dataview.getCodeName()?lower_case}', parameterName: '${dataview.getCodeName()?lower_case}' },
        ];
        </#if>
        <#--  END：是否应用实体视图  -->
        <#else>
        <#--  BEGIN：是否应用实体视图  -->
        <#if dataview.isPSDEView()>
        <#assign appDataEntity = dataview.getPSAppDataEntity()/>
        const parameters: any[] = [
            { pathName: '${srfpluralize(appDataEntity.codeName)?lower_case}', parameterName: '${appDataEntity.getCodeName()?lower_case}' },
        ];
        <#else>
        const parameters: any[] = [];
        </#if>
        <#--  END：是否应用实体视图  -->
        </#if>
        </#if>
        <#--  END：准备参数  -->
        <#if dataview.isRedirectView()>
        <#if dataview.getViewType() == "DEWFDATAREDIRECTVIEW" || dataview.getViewType() == "APPWFREDIRECTVIEW">
        <#-- 应用全局流程工作重定向视图and实体全局流程数据重定向视图start -->
        if(fullargs && fullargs.length >0){
           <#noparse>window.open(`${fullargs[0].viewurl}srfworklist=${fullargs[0].wfworklistid}`);</#noparse>
           window.addEventListener("message",(event:any) =>{
            const data:any = event.data;
            if (Object.is(data.identification,'WF')){
                return ;
            }
            if(Object.is(data.status,'OK')){
                let xData:any = this.$refs.grid;
                if (xData.refresh && xData.refresh instanceof Function) {
                    setTimeout(() => {
                        xData.refresh();
                    }, 1000);
                }
            }
           })
        }else{
           console.error("重定向地址有误");
        }
        <#-- 应用全局流程工作重定向视图and实体全局流程数据重定向视图end -->
        <#else>
        <#-- 实体数据重定向视图start -->
        <#if curOPenLogicRefView?? && curOPenLogicRefView.getPSAppDataEntity()??>
        this.appUIService.getService('${curOPenLogicRefView.getPSAppDataEntity().getCodeName()?lower_case}').then((service) => {
            if(!service) {
                this.$Notice.error({desc: '重定向服务不存在！'})
                return;
            }
            const srfkey: any = tempContext.${curOPenLogicRefView.getPSAppDataEntity().getCodeName()?lower_case};
            service.getRDAppView(srfkey,false).then((res:any) =>{
                if(res){
                    this.$openViewService.openView(res, tempContext, { ...this.viewparams, srfkey });
                }else{
                    console.error("未查找到重定向视图")
                }
            })
        })
        </#if>
        <#-- 实体数据重定向视图end -->
        </#if>
        <#elseif dataview.getOpenMode() == 'INDEXVIEWTAB' || dataview.getOpenMode() == ''>
        <#--  打开顶级分页视图 -->
        const _this: any = this;
        const openIndexViewTab = (data: any) => {
            const routePath = this.$viewTool.buildUpRoutePath(this.$route, tempContext, deResParameters, parameters, args, data);
            <#if dataview.getViewType() == "DEWFDYNAEDITVIEW" >
            this.$router.push(routePath+'?userTaskId='+this.viewparams.userTaskId);
            <#else>
            this.$router.push(routePath);
            </#if>
        }
        openIndexViewTab(data);
        <#elseif dataview.getOpenMode() == 'POPUPAPP'>
        <#--  打开独立程序弹出  -->
        const _this: any = this;
        const routePath = this.$viewTool.buildUpRoutePath(this.$route, tempContext, deResParameters, parameters, args, data);
        window.open('./#'+routePath, '_blank');
        <#elseif dataview.getOpenMode() = 'POPUPMODAL'>
        <#--  打开模态  -->
        const _this: any = this;
        const openPopupModal = (view: any, data: any) => {
            let container: Subject<any> = this.$appmodal.openModal(view, tempContext, data);
            container.subscribe((result: any) => {
                if (!result || !Object.is(result.ret, 'OK')) {
                    return;
                }
                if (!xData || !(xData.refresh instanceof Function)) {
                    return;
                }
                xData.refresh(result.datas);
            });
        }
        const view: any = {
            viewname: '${srffilepath2(dataview.getCodeName())}', 
            height: ${dataview.getHeight()?c}, 
            width: ${dataview.getWidth()?c},  
            title: this.<@getViewLanguageTitle dataview />,
        };
        openPopupModal(view, data);
        <#elseif dataview.getOpenMode()?index_of('DRAWER') == 0>
        <#--  打开抽屉  -->
        const _this: any = this;
        const openDrawer = (view: any, data: any) => {
            let container: Subject<any> = this.$appdrawer.openDrawer(view, tempContext, data);
            container.subscribe((result: any) => {
                if (!result || !Object.is(result.ret, 'OK')) {
                    return;
                }
                if (!xData || !(xData.refresh instanceof Function)) {
                    return;
                }
                xData.refresh(result.datas);
            });
        }
        const view: any = {
            viewname: '${srffilepath2(dataview.getCodeName())}', 
            height: ${dataview.getHeight()?c}, 
            width: ${dataview.getWidth()?c},  
            title: this.<@getViewLanguageTitle dataview />,
            placement: '${dataview.getOpenMode()}',
        };
        openDrawer(view, data);
        <#elseif dataview.getOpenMode() == 'POPOVER'>
        <#--  打开气泡卡片  -->
        const _this: any = this;
        const openPopOver = (view: any, data: any) => {
            let container: Subject<any> = this.$apppopover.openPop($event, view, tempContext, data);
            container.subscribe((result: any) => {
                if (!result || !Object.is(result.ret, 'OK')) {
                    return;
                }
                if (!xData || !(xData.refresh instanceof Function)) {
                    return;
                }
                xData.refresh(result.datas);
            });
        }
        const view: any = {
            viewname: '${srffilepath2(dataview.getCodeName())}', 
            height: ${dataview.getHeight()?c}, 
            width: ${dataview.getWidth()?c},  
            title: this.<@getViewLanguageTitle dataview />,
            placement: '${dataview.getOpenMode()}',
        };
        openPopOver(view, data);
        <#else>
        this.$Notice.warning({ title: '错误', desc: this.<@getViewLanguageTitle dataview />+'不支持该模式打开' });
        </#if>
    <#else>
    this.$Notice.warning({ title: '错误', desc: '未指定关系视图' });
    </#if>
    }
</#if>
